package cc.magicjson.jpa.datasouce.service;


import cc.magicjson.jpa.datasouce.bo.RemoteUserBo;
import cc.magicjson.jpa.datasouce.bo.SysUserBo;
import cc.magicjson.jpa.datasouce.convert.SysUserBoConvert;
import cc.magicjson.jpa.datasouce.entity.SysUser;
import cc.magicjson.jpa.datasouce.repository.UserRepository;
import cc.magicjson.jpa.datasouce.utils.MapstructUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("mapUserService")
public class UserService {

    @Autowired
    private SysUserBoConvert sysUserBoConvert;


    private final UserRepository userRepository;

    @Autowired
    private MapstructUtils mapstructUtils;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public void createUser(RemoteUserBo remoteUserBo) {
        // 使用 MapstructUtils 进行对象转换
        SysUserBo sysUserBo = sysUserBoConvert.convert(remoteUserBo);

        // 将 SysUserBo 转换为 SysUser 实体，准备保存
        SysUser sysUser = mapstructUtils.convert(sysUserBo, SysUser.class);

        // 保存到数据库
        userRepository.save(sysUser);
    }
}
